const deviceModel = require("../../../model/device");
const channelModel = require("../../../model/channel");
const keepAliveAck = require("../../ack/keepaliveAck");
const log4js = require('../../../data/log');
const logger = log4js.getLogger('sip');
const sip = require("sip");

module.exports={
    /**
     * 心跳处理
     * @param rq
     * @param deviceId
     * @param channelId
     * @returns {Promise<void>}
     */
    async handle(rq, deviceId, channelId){
        logger.info(`deviceId=${deviceId} channelId=${channelId} keepalive只标记online，host信息没多大作用`);

        await deviceModel.updateOnline(deviceId, 1);
        // 有些通道号填写有问题，下面一句可以默认生成channelId与deviceId相同的子通道
        // await channelModel.updateOnline(deviceId, channelId, 1);
        let alive = keepAliveAck.generate(rq);
        sip.send(alive);
    }
}
